﻿using System;
using System.Xml.Serialization;

namespace VisualSearch.Core
{
    [XmlRoot(Namespace = "http://a9.com/-/spec/opensearch/1.1/")]
    public class OpenSearchDescription
    {
        [XmlElement(Order = 0)]
        public string ShortName { get; set; }

        [XmlElement(ElementName = "Url", Order = 1)]
        public HtmlTemplate HtmlTemplateUrl { get; set; }

        [XmlElement(ElementName = "Url", Order = 2)]
        public SuggestionTemplate SuggestionTemplateUrl { get; set; }

        [XmlElement(ElementName = "Image", Order = 3)]
        public Image SearchImage { get; set; }

        public class HtmlTemplate
        {
            public HtmlTemplate()
            {
                this.Type = "text/html";
            }

            [XmlAttribute("type")]
            public string Type { get; set; }

            [XmlAttribute("template")]
            public string TemplateUrl { get; set; }
        }
        public class SuggestionTemplate
        {
            public SuggestionTemplate()
            {
                this.Type = "application/x-suggestions+xml";
            }
            [XmlAttribute("type")]
            public string Type { get; set; }
            [XmlAttribute("template")]
            public string TemplateUrl { get; set; }
        }

        public class Image
        {
            public Image()
            {
                Type = "image/icon";
            }
            [XmlAttribute("width")]
            public int Width { get; set; }
            [XmlAttribute("height")]
            public int Height { get; set; }
            [XmlAttribute("type")]
            public string Type { get; set; }
            [XmlText]
            public string Url { get; set; }
        }
    }
}
